package org.za.communication.message;

import java.nio.charset.Charset;
import java.nio.charset.CharsetEncoder;

import org.apache.mina.core.buffer.IoBuffer;

import android.R.string;

public class Loginmessage extends BaseMessage {
	private byte[] key = new byte[4];
	private String mobile;
	private String password;

	public Loginmessage() {
		super();
		this.msgId = 0x02;
	}

	public byte[] getKey() {
		return key;
	}

	public void setKey(byte[] key) {
		this.key = key;
	}

	public String getMobile() {
		return mobile;
	}

	public void setMobile(String mobile) {
		this.mobile = mobile;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	@Override
	public IoBuffer getData() {
		try {
			buf = IoBuffer.allocate(2).setAutoExpand(true);
			buf.putUnsignedShort(this.getMsgId());
			buf.put(key);
			buf.putString(mobile, Charset.forName("utf-8").newEncoder());
			buf.put(new byte[1]);
			buf.putString(password, Charset.forName("utf-8").newEncoder());
			buf.flip();
			return buf;
		} catch (Exception e) {
			return null;
		}

	}

	@Override
	public void setData(IoBuffer buf) {
		// TODO Auto-generated method stub

	}

}
